/** 
 * 平台数据接口。
 * 由于每款游戏通常需要发布到多个平台上，所以提取出一个统一的接口用于开发者获取平台数据信息
 * 推荐开发者通过这种方式封装平台逻辑，以保证整体结构的稳定
 * 由于不同平台的接口形式各有不同，白鹭推荐开发者将所有接口封装为基于 Promise 的异步形式
 */
declare interface Platform {

    getUserInfo(): Promise<any>;

    login(): Promise<any>;
    createInnerAudioContext(): any;
    showModal(data): any;
    request(url, data, callback?, method?, header?): Promise<any>;
    shareAppMessage(data?): Promise<any>;
    getSettingInfo(): any;
    saveImageToPhotosAlbum(path, success?, fail?): any;
    openSetting(): any;
    createOpenSettingButton(data: any): any;
    getSystemInfo(data: any): any;
    getLaunchOptionsSync(callback): Promise<any>;
    createGameClubButton(data): any;
    getSystemInfoSync(callback): Promise<any>;
    openCustomerServiceConversation(data): any;
    previewImage(data): any;
    setUserCloudStorage(data, callback?): Promise<any>;
    callPlatformMethod(name,data): Promise<any>;
    createWorker(path:string):Promise<any>;
}
declare const wx: any;
class DebugPlatform implements Platform {
    async getUserInfo() {
        return { nickName: "username" }
    }
    async login() {
        return { code: "code" }
    }
    async createInnerAudioContext() {

    }
    async showModal(data) {

    }
    private loader: egret.URLLoader;
    async request(url, data, callback?, method?, header?) {
        if (!this.loader) {
            this.loader = new egret.URLLoader();
            this.loader.addEventListener(egret.Event.COMPLETE, this.onPostComplete, this);
        }


        data["code"] = "081a2pXX1TogZS0dkPXX1ZDhXX1a2pXf";
        var dataDict = { "url": url, "method": method, params: data, headers: header };

        var request: egret.URLRequest = new egret.URLRequest();
        request.url = "http:////wxapp.xyhuyu.cn/";
        request.method = egret.URLRequestMethod.POST;
        request.data = dataDict;
        this.loader.load(request);
    }
    private onPostComplete(event: egret.Event): void {
        var loader: egret.URLLoader = <egret.URLLoader>event.target;
        var data: egret.URLVariables = loader.data;
    }
    async shareAppMessage(data?) {

    }
    async getSettingInfo() {

    }
    async saveImageToPhotosAlbum(path, success?, fail?) {

    }
    async openSetting() {

    }
    async createOpenSettingButton(data: any) {

    }
    async getSystemInfo(data) {

    }
    async getSystemInfoSync(data) {

    }
    async getLaunchOptionsSync(callback) {

    }
    async createGameClubButton(data) {

    }
    async openCustomerServiceConversation(data) {

    }
    async previewImage(data) {

    }
    async setUserCloudStorage(data, callback?) {

    }
    async callPlatformMethod(name,data){
        
    }
    async createWorker(path:string){}
}


if (!window.platform) {
    window.platform = new DebugPlatform();
}



declare let platform: Platform;

declare interface Window {

    platform: Platform
}





